﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using TyMES.Model.Record;


namespace TyMES.ViewModel.Record.RepairRecordVMs
{
    public partial class RepairRecordListVM : BasePagedListVM<RepairRecord_View, RepairRecordSearcher>
    {

        protected override IEnumerable<IGridColumn<RepairRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<RepairRecord_View>>{
                this.MakeGridHeader(x => x.LineCode),
                this.MakeGridHeader(x => x.OperationCode),
                this.MakeGridHeader(x => x.OperationName),
                this.MakeGridHeader(x => x.OldSN),
                this.MakeGridHeader(x => x.CurrentSN),
                this.MakeGridHeader(x => x.TZMaterialCode),
                this.MakeGridHeader(x => x.RepairStatus),
                this.MakeGridHeader(x => x.Description),
                this.MakeGridHeader(x => x.uploadTime),
                this.MakeGridHeader(x => x.uploadFlag),
                this.MakeGridHeader(x => x.Filed1),
                this.MakeGridHeader(x => x.Filed2),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<RepairRecord_View> GetSearchQuery()
        {
            var query = DC.Set<RepairRecord>()
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckContain(Searcher.OperationCode, x=>x.OperationCode)
                .CheckContain(Searcher.OperationName, x=>x.OperationName)
                .CheckContain(Searcher.OldSN, x=>x.OldSN)
                .CheckContain(Searcher.CurrentSN, x=>x.CurrentSN)
                .CheckContain(Searcher.TZMaterialCode, x=>x.TZMaterialCode)
                .CheckContain(Searcher.RepairStatus, x=>x.RepairStatus)
                .CheckContain(Searcher.Description, x=>x.Description)
                .CheckContain(Searcher.uploadTime, x=>x.uploadTime)
                .CheckEqual(Searcher.uploadFlag, x=>x.uploadFlag)
                .CheckContain(Searcher.Filed1, x=>x.Filed1)
                .CheckContain(Searcher.Filed2, x=>x.Filed2)
                .Select(x => new RepairRecord_View
                {
				    ID = x.ID,
                    LineCode = x.LineCode,
                    OperationCode = x.OperationCode,
                    OperationName = x.OperationName,
                    OldSN = x.OldSN,
                    CurrentSN = x.CurrentSN,
                    TZMaterialCode = x.TZMaterialCode,
                    RepairStatus = x.RepairStatus,
                    Description = x.Description,
                    uploadTime = x.uploadTime,
                    uploadFlag = x.uploadFlag,
                    Filed1 = x.Filed1,
                    Filed2 = x.Filed2,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class RepairRecord_View : RepairRecord{

    }
}
